package org.yang.novel.down.service.impl;

import static org.yang.common.Msg.*;

import org.yang.common.Msg;
import org.yang.novel.down.dao.InfoMapper;
import org.yang.novel.down.entity.Info;
import org.yang.novel.down.service.InfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小说详情服务实现
 * @author shichenyang
 * @email gyv12345@163.com
 * @date 2019/01/07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class InfoServiceImpl implements InfoService {
    @Resource
    private InfoMapper infoMapper;

    @Override
    public Msg addInfo(Info info) {
        int i=  infoMapper.insert(info);
        return i>0?ok(ADD_SUCCESS):err(ADD_ERR);
    }

    @Override
    public Msg updateInfo(Info info) {
        int i= infoMapper.updateByParam(info);
        return i>0?ok(UPDATE_SUCCESS):err(UPDATE_ERR);
    }

    @Override
    public Msg delInfo(Info info) {
        int i=infoMapper.del(info.getId());
        return i>0?ok(DEL_SUCCESS):err(DEL_ERR);
    }

    @Override
    public PageInfo getInfos(Info info, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Info> infos=infoMapper.list(info);
        PageInfo pi=new PageInfo(infos);
        return pi;
    }
}
